from django.db import models

class User(models.Model):
    user_id = models.AutoField(primary_key=True, unique=True, verbose_name="用户ID")
    name = models.CharField(max_length=255, unique=True, null=False, verbose_name='用户名')
    gender = models.CharField(max_length=255, null=False, choices=[(1, "男"), (0, "女")], verbose_name='用户性别')
    email = models.EmailField(max_length=255, unique=True, null=False, verbose_name='用户邮箱')
    mobile = models.CharField(max_length=11, unique=True, null=False, verbose_name='用户手机号码')
    password = models.CharField(max_length=60, null=False, verbose_name='用户密码')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='用户注册时间')

    def get_gender_display(self):
        if self.gender == '1':
            return '男'
        else:
            return '女'

    class Meta:
        db_table = 'user'

class UserAddress(models.Model):
    user_address_id = models.AutoField(primary_key=True, unique=True, verbose_name="收件地址ID")
    email = models.EmailField(max_length=255, null=False, verbose_name='用户邮箱')
    recipient_name = models.CharField(max_length=255, unique=True, null=False, verbose_name='收件人姓名')
    recipient_address = models.CharField(max_length=255, null=False, verbose_name='收件地址')
    recipient_mobile = models.CharField(max_length=11, null=False, verbose_name='收件人手机号')
    district = models.CharField(max_length=255, null=False, verbose_name='地区')
    default = models.BooleanField(default=False, verbose_name='是否默认地址')
    # create_time = models.DateTimeField(auto_now_add=True, verbose_name='收货地址创建时间')

    def __str__(self):
        return f"{self.recipient_name} - {self.recipient_address} - {self.recipient_mobile}"

    class Meta:
        db_table = 'user_address'